//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#include "SpecificTimeDerivative.h"

registerMooseObject("snakeApp", SpecificTimeDerivative);

template <>
InputParameters
validParams<SpecificTimeDerivative>()
{
  InputParameters params = validParams<TimeDerivative>();
  // Density may be changing with deformation, so we must integrate
  // over current volume by setting the use_displaced_mesh flag.
  params.set<bool>("use_displaced_mesh") = true;

  params.addParam<MaterialPropertyName>(
      "cp", "cp", "Property name of the specific heat material property");
  params.addParam<MaterialPropertyName>(
      "rho", "rho", "Property name of the density material property");
   return params;
}

SpecificTimeDerivative::SpecificTimeDerivative(
    const InputParameters & parameters)
  : DerivativeMaterialInterface<JvarMapKernelInterface<TimeDerivative>>(parameters),
    _specific_heat(getMaterialProperty<Real>("cp")),
    _d_specific_heat_dT(getMaterialPropertyDerivative<Real>("cp", _var.name())),
    _density(getMaterialProperty<Real>("rho")),
    _d_density_dT(getMaterialPropertyDerivative<Real>("rho", _var.name()))
{
 
}

Real
SpecificTimeDerivative::computeQpResidual()
{
  
  return _specific_heat[_qp] * _density[_qp] * TimeDerivative::computeQpResidual();
}

Real
SpecificTimeDerivative::computeQpJacobian()
{
  const Real dT = TimeDerivative::computeQpResidual();

  // on-diagonal Jacobian with all terms that may depend on the kernel variable
  return _specific_heat[_qp] * _density[_qp] * TimeDerivative::computeQpJacobian() +
         _d_specific_heat_dT[_qp] * _phi[_j][_qp] * _density[_qp] * dT +
         _specific_heat[_qp] * _d_density_dT[_qp] * _phi[_j][_qp] * dT;
}


